/* Tablets */

input[type="submit"],
button {
  -webkit-appearance: none;
  appearance: none;
}

@media (max-width: 1024px) {
  /* Basic */

  html {
    -webkit-text-size-adjust: 100%;
  }

  td,
  th {
    padding: 10px;
    font-size: 14px;
  }

  /* Changelist */

  #toolbar {
    border: none;
    padding: 15px;
  }

  #changelist-search {
    > div {
      display: flex;
      flex-wrap: nowrap;
      max-width: 480px;
    }

    label {
      line-height: 22px;
    }
  }

  #toolbar form {
    #searchbar {
      flex: 1 0 auto;
      width: 0;
      height: 22px;
      margin: 0 10px 0 6px;
    }

    input[type="submit"] {
      flex: 0 1 auto;
    }
  }

  #changelist-search .quiet {
    width: 0;
    flex: 1 0 auto;
    margin: 5px 0 0 25px;
  }

  #changelist .actions {
    display: flex;
    flex-wrap: wrap;
    padding: 15px 0;

    &.selected {
      border: none;
    }

    label {
      display: flex;
    }

    select {
      background: var(--body-bg);
    }

    .button {
      min-width: 48px;
      margin: 0 10px;
    }

    span {
      &.all,
      &.clear,
      &.question,
      &.action-counter {
        font-size: 11px;
        margin: 0 10px 0 0;
      }
    }
  }

  #changelist {
    .paginator {
      border-top-color: var(--hairline-color);

      /* XXX Is this used at all? */
    }

    .results + .paginator {
      border-top: none;
    }
  }

  /* Forms */

  label {
    font-size: 14px;
  }

  .form-row {
    input {
      &[type="text"],
      &[type="password"],
      &[type="email"],
      &[type="url"],
      &[type="tel"],
      &[type="number"] {
        box-sizing: border-box;
        margin: 0;
        padding: 6px 8px;
        min-height: 36px;
        font-size: 14px;
      }
    }

    textarea,
    select,
    .vTextField {
      box-sizing: border-box;
      margin: 0;
      padding: 6px 8px;
      min-height: 36px;
      font-size: 14px;
    }

    select {
      height: 36px;

      &[multiple] {
        height: auto;
        min-height: 0;
      }
    }
  }

  fieldset .fieldBox {
    float: none;
    margin: 0 -10px;
    padding: 0 10px;

    + .fieldBox {
      margin-top: 10px;
      padding-top: 10px;
      border-top: 1px solid var(--hairline-color);
    }
  }

  textarea {
    max-width: 100%;
    max-height: 120px;
  }

  .aligned {
    label {
      padding-top: 6px;
    }

    .related-lookup,
    .datetimeshortcuts,
    .related-lookup + strong {
      align-self: center;
      margin-left: 15px;
    }
  }

  form .aligned ul.radiolist {
    margin-left: 2px;
  }

  /* Related widget */

  .related-widget-wrapper {
    float: none;
  }

  .related-widget-wrapper-link + .selector {
    max-width: calc(100% - 30px);
    margin-right: 15px;
  }

  select + .related-widget-wrapper-link,
  .related-widget-wrapper-link + .related-widget-wrapper-link {
    margin-left: 10px;
  }

  /* Selector */

  .selector {
    display: flex;
    width: 100%;

    .selector-filter {
      display: flex;
      align-items: center;

      label {
        margin: 0 8px 0 0;
      }

      input {
        width: auto;
        min-height: 0;
        flex: 1 1;
      }
    }
  }

  .selector-available,
  .selector-chosen {
    width: auto;
    flex: 1 1;
    display: flex;
    flex-direction: column;
  }

  .selector {
    select {
      width: 100%;
      flex: 1 0 auto;
      margin-bottom: 5px;
    }

    ul.selector-chooser {
      width: 26px;
      height: 52px;
      padding: 2px 0;
      margin: auto 15px;
      border-radius: 20px;
      transform: translateY(-10px);
    }
  }

  .selector-add,
  .selector-remove {
    width: 20px;
    height: 20px;
    background-size: 20px auto;
  }

  .selector-add {
    background-position: 0 -120px;
  }

  .selector-remove {
    background-position: 0 -80px;
  }

  a {
    &.selector-chooseall,
    &.selector-clearall {
      align-self: center;
    }
  }

  .stacked {
    flex-direction: column;
    max-width: 480px;

    > * {
      flex: 0 1 auto;
    }

    select {
      margin-bottom: 0;
    }

    .selector-available,
    .selector-chosen {
      width: auto;
    }

    ul.selector-chooser {
      width: 52px;
      height: 26px;
      padding: 0 2px;
      margin: 15px auto;
      transform: none;
    }

    .selector-chooser li {
      padding: 3px;
    }

    .selector-add,
    .selector-remove {
      background-size: 20px auto;
    }

    .selector-add,
    .active.selector-add {
      background-position: 0 -40px;
    }
  }

  .active.selector-add {
    &:focus,
    &:hover {
      background-position: 0 -140px;
    }
  }

  .stacked {
    .active.selector-add {
      &:focus,
      &:hover {
        background-position: 0 -60px;
      }
    }

    .selector-remove,
    .active.selector-remove {
      background-position: 0 0;
    }
  }

  .active.selector-remove {
    &:focus,
    &:hover {
      background-position: 0 -100px;
    }
  }

  .stacked .active.selector-remove {
    &:focus,
    &:hover {
      background-position: 0 -20px;
    }
  }

  .help-tooltip,
  .selector .help-icon {
    display: none;
  }

  form .form-row p.datetime {
    width: 100%;
  }

  .datetime {
    input {
      width: 50%;
      max-width: 120px;
    }

    span {
      font-size: 13px;
    }

    .timezonewarning {
      display: block;
      font-size: 11px;
      color: var(--body-quiet-color);
    }
  }

  .datetimeshortcuts {
    color: var(--border-color);

    /* XXX Redundant, .datetime span also sets #ccc */
  }

  .form-row .datetime input {
    &.vDateField,
    &.vTimeField {
      width: 75%;
    }
  }

  .inline-group {
    overflow: auto;
  }

  /* Messages */

  ul.messagelist li {
    padding-left: 55px;
    background-position: 30px 12px;

    &.error {
      background-position: 30px 12px;
    }

    &.warning {
      background-position: 30px 14px;
    }
  }

  /* Login */

  .login {
    #header {
      padding: 15px 20px;
    }

    #branding h1 {
      margin: 0;
    }
  }

  /* GIS */

  div.olMap {
    max-width: calc(100vw - 30px);
    max-height: 300px;
  }

  .olMap + .clear_features {
    display: block;
    margin-top: 10px;
  }

  /* Docs */

  .module table.xfull {
    width: 100%;
  }

  pre.literal-block {
    overflow: auto;
  }
}

/* Mobile */

@media (max-width: 767px) {

  /* Changelist */

  #changelist {
    align-items: stretch;
    flex-direction: column;
  }

  #changelist .actions {
    label {
      flex: 1 1;
    }

    select {
      flex: 1 0;
      width: 100%;
    }

    span {
      flex: 1 0 100%;
    }
  }

  .object-tools {
    float: none;
    margin: 0 0 15px;
    padding: 0;
    overflow: hidden;

    li {
      height: auto;
      margin-left: 0;

      + li {
        margin-left: 15px;
      }
    }
  }

  /* Forms */

  .form-row {
    padding: 15px 0;
  }

  .aligned .form-row {
    display: flex;
    flex-wrap: wrap;
    max-width: 100vw;

    > div {
      display: flex;
      flex-wrap: wrap;
      max-width: 100vw;
      width: calc(100vw - 30px);
    }
  }

  textarea {
    max-width: none;
  }

  .vURLField {
    width: auto;
  }

  fieldset {
    .fieldBox + .fieldBox {
      margin-top: 15px;
      padding-top: 15px;
    }

    &.collapsed .form-row {
      display: none;
    }
  }

  .aligned {
    label {
      width: 100%;
      padding: 0 0 10px;

      &:after {
        max-height: 0;
      }
    }

    .form-row {
      input,
      select,
      textarea {
        flex: 1 1 auto;
        max-width: 100%;
      }
    }

    .checkbox-row {
      align-items: center;

      input {
        flex: 0 1 auto;
        margin: 0;
      }
    }

    .vCheckboxLabel {
      flex: 1 0;
      padding: 1px 0 0 5px;
    }

    label + {
      p {
        padding: 0;
        margin-left: 0;
      }

      div {
        &.help,
        &.readonly {
          padding: 0;
          margin-left: 0;
        }
      }
    }

    p.file-upload {
      margin-left: 0;
      font-size: 13px;
    }
  }

  span.clearable-file-input {
    margin-left: 15px;

    label {
      font-size: 13px;
      padding-bottom: 0;
    }
  }

  .aligned .timezonewarning {
    flex: 1 0 100%;
    margin-top: 5px;
  }

  form .aligned {
    .form-row div.help {
      width: 100%;
      margin: 5px 0 0;
      padding: 0;
    }

    ul {
      margin-left: 0;
      padding-left: 0;

      &.radiolist {
        margin-right: 15px;
        margin-bottom: -3px;

        &:not(.inline) li + li {
          margin-top: 5px;
        }
      }
    }
  }

  /* Related widget */

  .related-widget-wrapper {
    width: 100%;
    display: flex;
    align-items: flex-start;

    .selector {
      order: 1;
    }

    > a {
      order: 2;
    }

    .radiolist ~ a {
      align-self: flex-end;
    }

    > select ~ a {
      align-self: center;
    }
  }

  select + .related-widget-wrapper-link,
  .related-widget-wrapper-link + .related-widget-wrapper-link {
    margin-left: 15px;
  }

  /* Selector */

  .selector {
    flex-direction: column;

    > * {
      float: none;
    }
  }

  .selector-available,
  .selector-chosen {
    margin-bottom: 0;
    flex: 1 1 auto;
  }

  .selector {
    select {
      max-height: 96px;
    }

    ul.selector-chooser {
      display: block;
      float: none;
      width: 52px;
      height: 26px;
      padding: 0 2px;
      margin: 15px auto 20px;
      transform: none;

      li {
        float: left;
      }
    }
  }

  .selector-remove {
    background-position: 0 0;
  }

  .active.selector-remove {
    &:focus,
    &:hover {
      background-position: 0 -20px;
    }
  }

  .selector-add {
    background-position: 0 -40px;
  }

  .active.selector-add {
    &:focus,
    &:hover {
      background-position: 0 -60px;
    }
  }

  /* Inlines */

  .inline-group {
    &[data-inline-type="stacked"] {
      .inline-related {
        border: 1px solid var(--hairline-color);
        border-radius: 4px;
        margin-top: 15px;
        overflow: auto;

        > * {
          box-sizing: border-box;
        }

        .module {
          padding: 0 10px;

          .form-row {
            border-top: 1px solid var(--hairline-color);
            border-bottom: none;

            &:first-child {
              border-top: none;
            }
          }
        }

        h3 {
          padding: 10px;
          border-top-width: 0;
          border-bottom-width: 2px;
          display: flex;
          flex-wrap: wrap;
          align-items: center;

          .inline_label {
            margin-right: auto;
          }

          span.delete {
            float: none;
            flex: 1 1 100%;
            margin-top: 5px;
          }
        }
      }

      .aligned {
        .form-row > div:not([class]),
        label {
          width: 100%;
        }
      }

      div.add-row {
        margin-top: 15px;
        border: 1px solid var(--hairline-color);
        border-radius: 4px;
      }
    }

    div.add-row,
    .tabular tr.add-row td {
      padding: 0;
    }

    div.add-row a,
    .tabular tr.add-row td a {
      display: block;
      padding: 8px 10px 8px 26px;
      background-position: 8px 9px;
    }
  }

  /* Submit row */

  .submit-row {
    padding: 10px 10px 0;
    margin: 0 0 15px;
    display: flex;
    flex-direction: column;

    > * {
      width: 100%;
    }

    input {
      float: none;
      margin: 0 0 10px;
      text-align: center;

      &.default {
        float: none;
        margin: 0 0 10px;
        text-align: center;
      }
    }

    a {
      float: none;
      margin: 0 0 10px;
      text-align: center;

      &.closelink {
        float: none;
        margin: 0 0 10px;
        text-align: center;
        padding: 10px 0;
      }
    }

    p.deletelink-box {
      order: 4;
    }
  }

  /* Messages */

  ul.messagelist li {
    padding-left: 40px;
    background-position: 15px 12px;

    &.error {
      background-position: 15px 12px;
    }

    &.warning {
      background-position: 15px 14px;
    }
  }

  /* Paginator */

  .paginator {
    .this-page {
      padding: 4px 10px;
    }

    a {
      &:link,
      &:visited {
        padding: 4px 10px;
      }
    }
  }

  /* Login */

  body.login {
    padding: 0 15px;
  }

  .login {
    #container {
      width: auto;
      max-width: 480px;
      margin: 50px auto;
    }

    #header,
    #content {
      padding: 15px;
    }

    #content-main {
      float: none;
    }

    .form-row {
      padding: 0;

      + .form-row {
        margin-top: 15px;
      }

      label {
        margin: 0 0 5px;
        line-height: 1.2;
      }
    }

    .submit-row {
      padding: 15px 0 0;
    }

    br {
      display: none;
    }

    .submit-row input {
      margin: 0;
      text-transform: uppercase;
    }
  }

  .errornote {
    margin: 0 0 20px;
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Calendar and clock */

  .calendarbox,
  .clockbox {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%);
    margin: 0;
    border: none;
    overflow: visible;
  }

  .calendarbox:before,
  .clockbox:before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    transform: translate(-50%, -50%);
  }

  .calendarbox > *,
  .clockbox > * {
    position: relative;
    z-index: 1;
  }

  .calendarbox {
    > div:first-child {
      z-index: 2;
    }

    .calendar {
      border-radius: 4px 4px 0 0;
      overflow: hidden;
    }
  }

  .clockbox h2 {
    border-radius: 4px 4px 0 0;
    overflow: hidden;
  }

  .calendarbox .calendar-cancel,
  .clockbox .calendar-cancel {
    border-radius: 0 0 4px 4px;
    overflow: hidden;
  }

  .calendar-shortcuts {
    padding: 10px 0;
    font-size: 12px;
    line-height: 12px;

    a {
      margin: 0 4px;
    }
  }

  .timelist a {
    background: var(--body-bg);
    padding: 4px;
  }

  .calendar-cancel {
    padding: 8px 10px;
  }

  .clockbox h2 {
    padding: 8px 15px;
  }

  .calendar caption {
    padding: 10px;
  }

  .calendarbox {
    .calendarnav-previous,
    .calendarnav-next {
      z-index: 1;
      top: 10px;
    }
  }

  /* History */

  table {
    &#change-history tbody {
      th,
      td {
        font-size: 13px;
        word-break: break-word;
      }

      th {
        width: auto;
      }
    }

    &.model tbody {
      th,
      td {
        font-size: 13px;
        word-break: break-word;
      }
    }
  }

  /* Docs */
}
